package com.yycx.module.bus.provider.handler.haiying.tasktodo.refundamount;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.common.mybatis.interceptor.GetInterceptor;
import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.module.bus.client.entity.BusDept;
import com.yycx.module.bus.client.entity.BusPayment;
import com.yycx.module.bus.provider.service.BusDeptService;
import com.yycx.module.bus.provider.service.BusPaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 退货款详情
 *
 * @author zyf
 */
@Component
public class HyRefundHkGetHandler implements GetInterceptor {

    @Autowired
    private BusPaymentService paymentService;

    @Autowired
    private BusDeptService deptService;


    @Override
    public ResultBody validate(CriteriaQuery cq, EntityMap params) {
        return ResultBody.ok();
    }

    @Override
    public void prepare(CriteriaQuery cq, EntityMap entityMap) {
        cq.select(BusPayment.class, "*");
    }

    @Override
    public void complete(CriteriaQuery cq, EntityMap map) {
        Long parentId = map.getLong("parentId");
        BusPayment parent = paymentService.getById(parentId);
        if (FlymeUtils.isNotEmpty(parent)) {
            Long deptId = parent.getDeptId();
            BusDept dept = deptService.getById(deptId);
            if (FlymeUtils.isNotEmpty(dept)) {
                map.put("parentDeptName", dept.getDeptName());
            }
            map.put("parentPaymentNo", parent.getPaymentNo());
            map.put("parentBankName", parent.getBankName());
            map.put("parentBankNo", parent.getBankNo());
            map.put("parentAmountDate", parent.getAmountDate());
            map.put("parentAmount", parent.getAmount());
        }
    }
}
